<?php


namespace app\jiangnan\controller;


use app\utils\JwtUtils;
use think\Controller;
use think\Db;

class Record extends Controller
{
    public function getList(){
        $accessToken=request()->header("accessToken");


        $userResult=JwtUtils::getDecodeToken($accessToken);
        $userInfo=Db::table("userinfo")->where("userid",$userResult["userid"])->find();
        if(empty($userInfo)){
             return json(["code"=>10030,'msg' => '用户未绑定房屋']);
        }
        $recordList=Db::table("cxyun_entry_exit_record")
            ->where("room_id",$userInfo["room_id"])
            ->order("id","desc")
            ->select();
        foreach ($recordList as &$value){
            if(!empty($value["entranceTime"])){
                $value["entranceTime"]=date("Y-m-d H:i:s",$value["entranceTime"]/1000);
            }
            if(!empty($value["exitTime"])){
                $value["exitTime"]=date("Y-m-d H:i:s",$value["exitTime"]/1000);
                $value["isEit"]=1;
            }

        }
        return json(["code"=>0,'msg' => '获取成功',"data"=>$recordList]);
    }

}